'use strict';

angular.module('app')
    .controller('forgottonController',[ '$rootScope', '$scope', '$http', '$state', function($rootScope, $scope, $http, $state) {
        $scope.user = {};
        $scope.login = function () {
            if(!this.$scope.user||!this.$scope.user.account||!this.$scope.user.password||this.$scope.user.account===null||this.$scope.user.password===null){
                console.log("不请求");
                return;
            }
            console.log($scope.user);
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : '/login',
                data: angular.toJson($scope.user)})
                .then(function(result) {
                    console.log('登录结果返回...');
                    console.log(result);
                    if (result.httpCode == 200) {
                        console.log("登录成功");
                        $state.go('main.index');
                    } else {
                        $scope.msg = result.msg;
                        $rootScope.$apply();
                    }
                });
        }
    } ]);